package com.example.gaussdb;

import com.example.bo.TestSzxBO;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class GaussMybatisMain {
    @Test
    public void mainTest() throws IOException {
        // 1.读取mybatis的核心配置文件(mybatis-config.xml)
        InputStream in = Resources.getResourceAsStream("mybatis-config.xml");
        // 2.通过配置信息获取一个SqlSessionFactory工厂对象
        SqlSessionFactory fac = new SqlSessionFactoryBuilder().build(in);
        // 3.通过工厂获取一个SqlSession对象
        SqlSession session = fac.openSession();
        // 4.通过namespace+id找到要执行的SQL语句并执行SQL语句
        List<TestSzxBO> list = session.selectList("TestSzxMapper.getList");
        // 5.输出结果
        list.forEach(i -> {
            System.out.println(i.toString());
        });
    }

}
